package com.qfedu.buy.server.manager.impl;

import com.qfedu.buy.common.config.SystemConfig;
import com.qfedu.buy.server.dao.UserdetailDao;
import com.qfedu.buy.server.dao.UserlevelDao;
import com.qfedu.buy.server.dao.UserscoreDao;
import com.qfedu.buy.server.dao.UserwalletDao;
import com.qfedu.buy.server.entity.Userlevel;
import com.qfedu.buy.server.entity.Userscore;
import com.qfedu.buy.server.manager.intf.UserInitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: NeighborBuy
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-01-26 15:02
 *
 * 通用接口层
 */
@Service
public class UserInitServiceImpl implements UserInitService {
    @Autowired
    private UserdetailDao userdetailDao;
    @Autowired
    private UserwalletDao userwalletDao;
    @Autowired
    private UserlevelDao userlevelDao;
    @Autowired
    private UserscoreDao userscoreDao;

    @Override
    @Transactional
    public int saveInit(Integer uid) {
        if(uid!=null) {
            userdetailDao.insertInit(uid);
            userwalletDao.insertInit(uid);
            userscoreDao.insert(new Userscore(uid, SystemConfig.USER_AWARD_REGISTER, SystemConfig.USER_SCORE_ADD, "新用户奖励" + SystemConfig.USER_AWARD_REGISTER + "积分"));
            userlevelDao.insert(new Userlevel(uid, 1, SystemConfig.levelMap.get(1), SystemConfig.USER_AWARD_REGISTER));
            return 1;
        }else {
            return -1;
        }
    }
}
